#include <iostream>
#include <string>


#include "grpcpp/grpcpp.h"

#include "greeter.grpc.pb.h"


void start() {
    // 1. 创建远程连接
    std::shared_ptr<grpc::Channel> channel = grpc::CreateChannel(
                                        "127.0.0.1:5555", 
                                        grpc::InsecureChannelCredentials()
                                    );

    // 2. 创建远程调用代理
    std::unique_ptr<Greeter::Stub> stub = Greeter::NewStub(channel);

    // 3. 调用远程函数
    // ::grpc::Status Greeter::Stub::sayHello(::grpc::ClientContext *context,
    //                                    const ::Request &request,
    //                                    ::Response *response)

    grpc::ClientContext context;
    Request  req;
    Response rep;

    req.set_name("yangxianpku");
    req.set_age(12);

    grpc::Status status = stub->sayHello(&context, req, &rep);

    if (status.ok() ) {
        std::cout << rep.message() << std::endl;
    } else {
        std::cerr << status.error_message() << std::endl;
    }
}


int main(int argc, char* argv[]) {
    start();

    return 0;
}